package com.lapelittle.order.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.SelectProvider;

import com.lapelittle.order.entity.AfterSaleOrder;
import com.lapelittle.order.mapper.provider.AfterSaleOrderProvider;
import com.lapelittle.order.query.AfterSaleOrderQuery;

import java.util.List;

@Mapper
public interface AfterSaleOrderMapper {
    
    @Select("SELECT * FROM after_sale_order WHERE after_sale_no = #{afterSaleNo}")
    AfterSaleOrder findByAfterSaleNo(String afterSaleNo);
    
    @Insert("<script>" +
            "INSERT INTO after_sale_order(" +
            "<if test='id != null'>id,</if> " +
            "after_sale_no, order_no, shop_name, product_image, " +
            "handle_time, product_props, price, quantity, refund_amount, actual_amount, " +
            "our_remark, after_sale_type, status, after_sale_reason, customer_remark, " +
            "return_logistics, return_logistics_no, delivery_logistics, delivery_logistics_no) " +
            "VALUES(" +
            "<if test='id != null'>#{id},</if> " +
            "#{afterSaleNo}, #{orderNo}, #{shopName}, #{productImage}, " +
            "#{handleTime}, #{productProps}, #{price}, #{quantity}, #{refundAmount}, #{actualAmount}, " +
            "#{ourRemark}, #{afterSaleType}, #{status}, #{afterSaleReason}, #{customerRemark}, " +
            "#{returnLogistics}, #{returnLogisticsNo}, #{deliveryLogistics}, #{deliveryLogisticsNo})" +
            "</script>")
    int insert(AfterSaleOrder order);
    
    @Update("UPDATE after_sale_order SET order_no = #{orderNo}, shop_name = #{shopName}, " +
            "product_image = #{productImage}, handle_time = #{handleTime}, " +
            "product_props = #{productProps}, price = #{price}, quantity = #{quantity}, " +
            "refund_amount = #{refundAmount}, actual_amount = #{actualAmount}, " +
            "our_remark = #{ourRemark}, after_sale_type = #{afterSaleType}, " +
            "status = #{status}, after_sale_reason = #{afterSaleReason}, " +
            "customer_remark = #{customerRemark}, return_logistics = #{returnLogistics}, " +
            "return_logistics_no = #{returnLogisticsNo}, delivery_logistics = #{deliveryLogistics}, " +
            "delivery_logistics_no = #{deliveryLogisticsNo}, id = #{id} " +
            "WHERE after_sale_no = #{afterSaleNo}")
    int update(AfterSaleOrder order);
    
    @SelectProvider(type = AfterSaleOrderProvider.class, method = "queryList")
    List<AfterSaleOrder> queryList(AfterSaleOrderQuery query);
    
    @SelectProvider(type = AfterSaleOrderProvider.class, method = "queryCount")
    Long queryCount(AfterSaleOrderQuery query);
}

